package cn.lookup.controller;

import cn.lookup.domain.Account;
import cn.lookup.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.WebParam;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    @Qualifier("accountService")
    private AccountService accountService;
    @RequestMapping(value = "/addAccount",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String addAccount(Account account) {
        try {
            accountService.addAccount(account);
            return "添加成功";
        } catch (IOException e) {
            e.printStackTrace();
            return "添加失敗";
        }
    }
    @RequestMapping("/accountList")
    public ModelAndView queryAllAccount(ModelAndView modelAndView) {
        List<Account> accounts = accountService.queryAllAccount();
        modelAndView.setViewName("accountList");
        modelAndView.addObject("accountList",accounts);
        return modelAndView;
    }
}
